package com.zmx.patients.adapter;

import android.app.Activity;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.wang.adapters.adapter.BaseAdapterRvList;
import com.wang.adapters.base.BaseViewHolder;
import com.zmx.patients.R;
import com.zmx.patients.pojo.Option;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 程序猿：胖胖祥
 * 时 间：2020/9/4  13:53
 * 功 能：
 */

public class IntelligentTitleAdapter extends BaseAdapterRvList<IntelligentTitleAdapter.ViewHolder, Option> {

    private Handler handler;
    private Integer type;
    private List<Option> lists;

    public IntelligentTitleAdapter(Activity activity,Handler handler,Integer type,List<Option> lists) {
        super(activity);

        this.handler = handler;
        this.type =type;
        this.lists = lists;

    }

    @Override
    protected void onBindVH(ViewHolder holder, int listPosition, Option s) {

        holder.title.setText(s.getName());
        holder.title.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (type == 0){

                    Message message = handler.obtainMessage();
                    message.what = 2;
                    message.obj = s;
                    handler.sendMessage(message);

                } else if (type == 1){

                    if (listPosition == lists.size()-1){

                        Message message = handler.obtainMessage();
                        message.what = 4;
                        message.obj = s;
                        handler.sendMessage(message);

                    }else{

                        if (s.isSelected()){

                            holder.title.setBackgroundResource(R.drawable.text_c);
                            s.setSelected(false);

                        }else{

                            holder.title.setBackgroundResource(R.drawable.text_d);
                            s.setSelected(true);

                        }

                    }



                }


            }
        });

    }

    @NonNull
    @Override
    protected ViewHolder onCreateVH(ViewGroup parent, LayoutInflater inflater) {
        IntelligentTitleAdapter.ViewHolder holder = new IntelligentTitleAdapter.ViewHolder(inflater.inflate(R.layout.adapter_intelligent_title, parent, false));
        return holder;

    }

    static class ViewHolder extends BaseViewHolder {

        @BindView(R.id.title)
        TextView title;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

    }

}
